import { ApiProperty, getSchemaPath } from "@nestjs/swagger";
import { CrudValidationGroups } from "@nestjsx/crud";
import { IsBoolean, IsOptional, IsString, ValidateNested } from "class-validator";
import { Column, Entity, OneToOne, PrimaryGeneratedColumn } from "typeorm";
import { Assets } from "./assets.entity";
import { BaseEntity } from "./base.entity";
import { file } from "./about/file";


const { CREATE, UPDATE } = CrudValidationGroups;


@Entity()
export class OperatingAssets extends BaseEntity {

  @ApiProperty({
    description: '经营性资产主键',
    required: false
  })
  @PrimaryGeneratedColumn()
  id: number;

  @ApiProperty({
    example: '承租人',
    description: '承租人',
    required: true
  })
  @IsString({ always: true })
  @IsOptional()
  @Column({
    type: "char",
    length: 255,
    nullable: true,
  })
  lessee ?: string 

  @ApiProperty({
    example: true,
    description: '签订合同',
    required: true
  })
  @IsBoolean({ always: true })
  @IsOptional()
  @Column({
    nullable: true,
  })
  contractSigned ?: boolean

  @ApiProperty({
    example: '合同期限',
    description: '合同期限',
    required: true
  })
  @IsString({ always: true })
  @IsOptional()
  @Column({
    type: "char",
    length: 255,
    nullable: true,
  })
  durationOfCooperation ?: string

  @ApiProperty({
    example: '支付情况',
    description: '支付情况',
    required: true
  })
  @IsString({ always: true })
  @IsOptional()
  @Column({
    type: "char",
    length: 255,
    nullable: true,
  })
  paymentStatus ?: string

  @ApiProperty({
    example: '合同状态',
    description: '合同状态',
    required: true
  })
  @IsString({ always: true })
  @IsOptional()
  @Column({
    type: "char",
    length: 255,
    nullable: true,
  })
  contractStatus ?: string

  @ApiProperty({
    example: '合同金额',
    description: '合同金额',
    required: true
  })
  // @IsDecimal({}, { always: true })
  // @IsNumber()
  @IsOptional()
  @Column({
    type: 'decimal',
    precision: 14,
    scale: 2,
    zerofill: false,
    nullable: true,
  })
  amount ?: number

  @ApiProperty({
    example: '备注',
    description: '备注',
    required: true
  })
  @IsString({ always: true })
  @IsOptional()
  @Column({
    type: "text",
    nullable: true,
  })
  remarks ?: string

  @ApiProperty({
    example: '经营性资产相关文件',
    description: '经营性资产相关文件',
    required: true
  })
  @ValidateNested()
  @IsOptional({ always: true })
  @Column({
    type: "simple-json",
    nullable: true,
  })
  relatedDocuments ?: file [];

  @ApiProperty({
    example: {},
    description: '所属资产',
    required: false,
    oneOf: [
      {
        type: 'Number'
      }, 
      { $ref: getSchemaPath(() => Assets)}
    ]
  })
  @OneToOne(() => Assets, Assets => Assets.operatingAssets)
  assets: () => Assets
}